﻿/************************************************************************************
* Copyright (c) 2019 All Rights Reserved.
*命名空间：Merge.Model
*文件名： ClassMathModel
*创建人： Liebeskind
*创建时间：2019/6/20 17:49:30
*描述
*=====================================================================
*修改标记
*修改时间：2019/6/20 17:49:30
*修改人：Liebeskind
*描述：有限集用枚举，“无限”和可扩充的集合不定义大小
************************************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MathNet.Numerics.LinearAlgebra.Double;

namespace Commonality.Model.Classify
{
    /// <summary>
    /// 定义特征向量变量n=4
    /// </summary>
    public struct Eigenvector
    {
        public LINE LINEi;
        /// <summary>
        /// 必要特征不能为""(NULL)
        /// </summary>
        public string PN;
        public KCAndBF KCAndBF;
        public Remark Remark;

        /// <summary>
        /// 特征向量(矩阵形式)
        /// </summary>
        public DenseMatrix MEigenvector;
    }
    public class CEigenvector
    {
        public LINE LINEi { get; set; }
        /// <summary>
        /// 必要特征不能为""(NULL)
        /// </summary>
        public string PN { get; set; }
        public KCAndBF KCAndBF { get; set; }
        public Remark Remark { get; set; }

        public string Storeroom { get; set; }
        public string Augmented1 { get; set; }
        public string Augmented2 { get; set; }
        public string Augmented3 { get; set; }
        public string Augmented4 { get; set; }
        public string Augmented5 { get; set; }
        public string Augmented6 { get; set; }
        public string Mo { get; set; }

        /// <summary>
        /// 特征向量(矩阵形式)
        /// </summary>
        public DenseMatrix MEigenvector;
        /// <summary>
        /// 特征向量字符格式
        /// </summary>
        public string StringEigenvector { get; set; }
        public CEigenvector(LINE LINEi, string PN, KCAndBF KCAndBF, Remark Remark, string Storeroom, string Augmented1, string Augmented2, string Augmented3, string Augmented4, string Augmented5, string Augmented6, string Mo, DenseMatrix MEigenvector)
        {
            this.LINEi = LINEi;
            this.PN = PN;
            this.KCAndBF = KCAndBF;
            this.Remark = Remark;
            this.MEigenvector = MEigenvector;
            this.Storeroom = Storeroom;
            this.Augmented1 = Augmented1;
            this.Augmented2 = Augmented2;
            this.Augmented3 = Augmented3;
            this.Augmented4 = Augmented4;
            this.Augmented5 = Augmented5;
            this.Augmented6 = Augmented6;
            this.Mo = Mo;
            StringEigenvector = (int)LINEi + "," + PN + "," + (int)KCAndBF + "," + (int)Remark;
        }
        //public CEigenvector(LINE LINEi, string PN, KCAndBF KCAndBF, Remark Remark, string Storeroom, string Mo, DenseMatrix MEigenvector)
        //{
        //    this.LINEi = LINEi;
        //    this.PN = PN;
        //    this.KCAndBF = KCAndBF;
        //    this.Remark = Remark;
        //    this.MEigenvector = MEigenvector;
        //    this.Storeroom = Storeroom;
        //    this.Mo = Mo;
        //    StringEigenvector = (int)LINEi + "," + PN + "," + (int)KCAndBF + "," + (int)Remark;
        //}
        public CEigenvector(LINE LINEi, string PN, KCAndBF KCAndBF, Remark Remark, string Storeroom, string Augmented1, string Augmented2, string Augmented3, string Augmented4, string Augmented5, string Augmented6, string Mo)
        {
            this.LINEi = LINEi;
            this.PN = PN;
            this.KCAndBF = KCAndBF;
            this.Remark = Remark;
            this.Storeroom = Storeroom;
            this.Augmented1 = Augmented1;
            this.Augmented2 = Augmented2;
            this.Augmented3 = Augmented3;
            this.Augmented4 = Augmented4;
            this.Augmented5 = Augmented5;
            this.Augmented6 = Augmented6;
            this.Mo = Mo;

            StringEigenvector = (int)LINEi + "," + PN + "," + (int)KCAndBF + "," + (int)Remark;
        }

        #region 特征的相关计算公共方法
        /// <summary>
        /// 特征比较
        /// </summary>
        /// <param name="cEigenvectorA"></param>
        /// <param name="cEigenvectorB"></param>
        /// <returns></returns>
        public static bool Comparison(ref CEigenvector cEigenvectorA, ref CEigenvector cEigenvectorB)
        {
            return (cEigenvectorA.LINEi == cEigenvectorB.LINEi &&
                cEigenvectorA.PN == cEigenvectorB.PN &&
                cEigenvectorA.Remark == cEigenvectorB.Remark &&
                cEigenvectorA.KCAndBF == cEigenvectorB.KCAndBF &&
                cEigenvectorA.Storeroom == cEigenvectorB.Storeroom &&
                cEigenvectorA.Augmented1 == cEigenvectorB.Augmented1 &&
                cEigenvectorA.Augmented2 == cEigenvectorB.Augmented2 &&
                cEigenvectorA.Augmented3 == cEigenvectorB.Augmented3 &&
                cEigenvectorA.Augmented4 == cEigenvectorB.Augmented4 &&
                cEigenvectorA.Augmented5 == cEigenvectorB.Augmented5 &&
                cEigenvectorA.Augmented6 == cEigenvectorB.Augmented6 &&
                cEigenvectorA.Mo == cEigenvectorB.Mo);
        }
        /// <summary>
        /// 是否是单位值（未定义类型/空特征）
        /// </summary>
        /// <param name="cEigenvector"></param>
        /// <returns></returns>
        public static bool isUnitVector(ref CEigenvector cEigenvector)
        {
            return (cEigenvector.LINEi == LINE.ZERO &&
                cEigenvector.PN == "" &&
                cEigenvector.Remark == Remark.ZERO &&
                cEigenvector.KCAndBF == KCAndBF.ZERO &&
                cEigenvector.Storeroom == "" &&
                cEigenvector.Augmented1 == "" &&
                cEigenvector.Augmented2 == "" &&
                cEigenvector.Augmented3 == "" &&
                cEigenvector.Augmented4 == "" &&
                cEigenvector.Augmented5 == "" &&
                cEigenvector.Augmented6 == "" &&
                cEigenvector.Mo == "");
        }
        /// <summary>
        /// 复位特征
        /// </summary>
        /// <param name="cEigenvector"></param>
        public static void RestEigenvector(ref CEigenvector cEigenvector)
        {
            cEigenvector = new CEigenvector(LINE.ZERO, "", KCAndBF.ZERO, Remark.ZERO, "", "", "", "", "", "", "", "",  DenseMatrix.OfArray(new[,] { { 0.0 }, { 0 }, { 0 }, { 0 } }));
        }
        /// <summary>
        /// 特征字符转特征类
        /// </summary>
        /// <param name="eig"></param>
        /// <param name="cEigenvector"></param>
        public static void EigenvectorString2C(string eig, ref CEigenvector cEigenvector)
        {
            string[] Eig = new string[10];
            Eig = eig.Split(',');
            cEigenvector = new CEigenvector((LINE)Convert.ToInt32(Eig[0]), Eig[1], (KCAndBF)Convert.ToInt32(Eig[2]), (Remark)Convert.ToInt32(Eig[3]), Eig[4], Eig[5], Eig[6], Eig[7], Eig[8], Eig[9], Eig[10], Eig[11]);
        }
        #endregion

    }

    /// <summary>
    /// Remark值域
    /// </summary>
    public enum Remark
    {
        /// <summary>
        /// 空集，Remark是类型的可选特征，若为ZERO则此类型不考虑方别向上的投影，全局中只存在不考虑Remark和考虑全体Remark值域两种情况
        /// </summary>
        ZERO = 0,
        ANSI = 1,
        ISO = 2,
        JIS = 3
    }
    /// <summary>
    /// KC+BF值域
    /// </summary>
    public enum KCAndBF
    {
        /// <summary>
        /// 空集，KC+BF作为毕业特征不能置NULL
        /// </summary>
        ZERO = 0,
        One = 1,
        Two = 2,
        Three = 3,
        Four = 4
    }
    public enum LINE
    {
        /// <summary>
        /// 空集，线别是类型的可选特征，若为NULL则此类型不考虑方别向上的投影，在类型集合中必须存在含有此特征值的类
        /// </summary>
        ZERO = 0,
        TB1_1FT_01 = 1,
        TB1_1FT_02 = 2,
        TB1_1FT_03 = 3,
        TB1_1FT_04 = 4,
        TB1_1FT_05 = 5,
        TB1_1FT_06 = 6,
        TB1_1FT_07 = 7,
        TB1_1FT_08 = 8,
        TB1_1FT_09 = 9,
        TB1_1FT_10 = 10,
        TB1_1FT_11 = 11,
        TB1_1FT_12 = 12,
        TB1_1FT_13 = 13,
        TB1_1FT_14 = 14,
        TB1_1FT_15 = 15,
        TB1_1FT_16 = 16
    }

}
